package cn.webrx;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Ex5 {
    public static void main(String[] args) {
        //合并文件操作
        File[] fs = new File("c:/abc/").listFiles();
        try {
            FileOutputStream fos = new FileOutputStream("c:/abc/b.zip");
            //for(int i=1;i<=20;i++){
            //    FileInputStream fis = new FileInputStream(String.format("c:/abc/g%02d",i));
            //    fos.write(fis.readAllBytes());
            //}

            for (File f : fs) {
                FileInputStream fis = new FileInputStream(f);
                fos.write(fis.readAllBytes());
            }
            fos.close();
        }catch(Exception e){

        }
    }
    public static void fen(String[] args) {
        //将文件分割20块 gradle-7.5-bin.zip
        String src = "c:/abc.zip";
        File file = new File(src);
        long filesize = file.length();
        long block = filesize % 20 == 0 ? filesize / 20 : filesize / 20 + filesize % 20;
        try (
                FileInputStream bis = new FileInputStream(src);
        ) {
            int len = 0;
            int index = 0;
            byte[] buf = new byte[(int) block];
            String dst = "";
            FileOutputStream bos = null;
            while ((len = bis.read(buf)) != -1) {
                dst = String.format("c:/abc/g%02d", ++index);
                bos = new FileOutputStream(dst);
                bos.write(buf, 0, len);
            }

        } catch (Exception e) {
        }


    }
}
